Skip to content

Comments

Switch to static piece arrays#1

Open
richardjs wants to merge 6 commits intomasterfrom
static-piece-arrays
Open

Switch to static piece arrays#1
richardjs wants to merge 6 commits intomasterfrom
static-piece-arrays

Conversation

@richardjs
Copy link
Owner

@richardjs richardjs commented May 1, 2023

Right now, the piece arrays on a State are stacks that start out empty and grow as pieces are added to the board. That means pieces will be in arbitrary orders, and if we need to know where (say) all the ants are, we either need to search through the entire array or cache references to ants elsewhere in State.

This branch changes State so that instead of growing as pieces are added to the board, the array starts full, and pieces are either on the board or in the hand (piece.coords.q == IN_HAND). This enables us to store pieces in the same order for every state, and easily look up specific pieces or pieces types.

(Branch is not ready to merge yet.)

Idea came from Pieces on the Chess Programming Wiki:

Other programs distinguish not only piece-type and color, but enumerate all 32 pieces from their initial position, which label or code does not change during the course of a game (even after a possible promotion of a pawn) and might be one-to-one associated with the bit-position of a 32-bit piece set, and/or are used to index a piece list containing the current square the piece resides on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant